/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelryweb.entities;

import java.io.Serializable;
import javax.persistence.*;
import ua.i.kotionokyurievna.jewelryweb.entities.OrderC;

/**
 *
 * @author Kateryna_Reznik
 */
@Entity
@NamedQueries({
    @NamedQuery ( name = "OrderItem.findById",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.itemId = :orderItemId"),
    @NamedQuery ( name = "OrderItem.findByOrderId",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.order = :order"),
    @NamedQuery ( name = "OrderItem.findByProductCatalogueId",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.productCatalog = :productCatalog"),
    @NamedQuery ( name = "OrderItem.findByPriceRange",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.price BETWEEN :minRangePrice AND :maxRangePrice"),
    @NamedQuery ( name = "OrderItem.findByPrice",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.price = :price"),
    @NamedQuery ( name = "OrderItem.findByProductCatalogueQuantity",
        query="SELECT oi.itemId, oi.order, oi.productCatalog, "
        + "oi.price, oi.quantity, oi.status "
        + "FROM OrderItem oi "
        + "WHERE oi.productCatalog = :productCatalog AND "
        + "oi.quantity = :quantity"),
})
@Table ( name = "orderitems")
public class OrderItem implements Serializable{
    @Id
    @Column (name = "item_id")
    @GeneratedValue ( strategy = GenerationType.TABLE)
    private int itemId;
    @ManyToOne
    @JoinColumn( name = "order_id")
    private OrderC order;
    @OneToOne
    @JoinColumn ( name = "productcatalogue_id" )
    private ProductCatalog productCatalog;
    private double price;
    private int quantity;
    @Enumerated ( EnumType.STRING )
    private OrderItemStatus status;

    public OrderItem() {
    }

    public OrderItem(OrderC order, ProductCatalog productCatalog, double price, 
            int quantity, OrderItemStatus status) {
        this.order = order;
        this.productCatalog = productCatalog;
        this.price = price;
        this.quantity = quantity;
        this.status = status;
    }

    public OrderItem(int itemId, OrderC order, ProductCatalog productCatalog, 
            double price, int quantity, OrderItemStatus status) {
        this.itemId = itemId;
        this.order = order;
        this.productCatalog = productCatalog;
        this.price = price;
        this.quantity = quantity;
        this.status = status;
    }

    public int getItemId() {
        return itemId;
    }

    public void setItemId(int itemId) {
        this.itemId = itemId;
    }

    public OrderC getOrder() {
        return order;
    }

    public ProductCatalog getProductCatalog() {
        return productCatalog;
    }

    public void setProductCatalog(ProductCatalog productCatalog) {
        this.productCatalog = productCatalog;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }

    public OrderItemStatus getStatus() {
        return status;
    }

    public void setStatus(OrderItemStatus status) {
        this.status = status;
    }

    @Override
    public String toString() {
        return "OrderItem{" + "itemId=" + itemId + ", order=" + order + 
                ", productCatalog=" + productCatalog + ", price=" + price + 
                ", quantity=" + quantity + ", status=" + status + '}';
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + (this.productCatalog != null ? this.productCatalog.hashCode() : 0);
        hash = 47 * hash + (int) (Double.doubleToLongBits(this.price) ^ (Double.doubleToLongBits(this.price) >>> 32));
        hash = 47 * hash + (this.status != null ? this.status.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final OrderItem other = (OrderItem) obj;
        if (this.productCatalog != other.productCatalog && (this.productCatalog == null || !this.productCatalog.equals(other.productCatalog))) {
            return false;
        }
        if (Double.doubleToLongBits(this.price) != Double.doubleToLongBits(other.price)) {
            return false;
        }
        if (this.status != other.status) {
            return false;
        }
        return true;
    }

   
    
    
}
